package logs

import (
	"bytes"
	"github.com/sirupsen/logrus"
	"io"
	"os"
)

func InitConfig() *logrus.Logger {
	log := logrus.New()
	writer1 := &bytes.Buffer{}
	writer2 := os.Stdout
	writer3, err := os.OpenFile("log.txt", os.O_WRONLY|os.O_CREATE, 0755)
	if err != nil {
		log.Fatalf("create file log.txt failed: %v", err)
	}
	log.SetOutput(io.MultiWriter(writer1, writer2, writer3))

	log.SetReportCaller(true)
	log.Formatter = &logrus.TextFormatter{
		DisableColors: false,
		FullTimestamp: true,
	}
	log.SetLevel(logrus.DebugLevel)

	iface := make(map[string]interface{})
	iface["123"] = 345

	log.WithFields(logrus.Fields{
		"user_id": 123,
		"ip":      "127.0.0.1",
	}).WithField(
		"test",
		"teststr",
	).Debugf("%s", iface)
	return log
}
